﻿using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Lilium.Web.Mvc.AjaxControlToolkit
{
	[RequiredResource(typeof(CommonToolkitScripts))]
	[RequiredResource(typeof(AnimationScripts))]
	[ToolkitScriptReference("CollapsiblePanel.CollapsiblePanelBehavior.js")]
	public class CollapsiblePanelExtender: ToolkitExtenderBase
	{
		public CollapsiblePanelExtender(string elementID)
			: base("AjaxControlToolkit.CollapsiblePanelBehavior", elementID)
		{
			EnableClientState = true;
		}

		#region public string CollapseControlID

		private string m_CollapseControlID;

		/// <summary>
		/// The server ID of the control to initiate the collapse of the target panel.  The panel will
		/// collapse when this control fires its client side "onclick" event.
		/// 
		/// If this value is the same as the value for "ExpandControlID", the CollapsiblePanel will
		/// toggle when this control is clicked.
		/// </summary>
		//[IDReferenceProperty(typeof(WebControl))]
		[DefaultValue("")]
		[SuppressMessage("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase", Justification = "Following ASP.NET AJAX pattern")]
		[ExtenderControlProperty]
		public string CollapseControlID { [DebuggerNonUserCodeAttribute] get { return m_CollapseControlID ?? string.Empty; } [DebuggerNonUserCodeAttribute] set { m_CollapseControlID = value; } }

		#endregion

		#region public string ExpandControlID

		private string m_ExpandControlID;

		/// <summary>
		/// The server ID of the control to initiate the expansion of the target panel.  The panel will
		/// opening when this control fires its client side "onclick" event.
		/// 
		/// If this value is the same as the value for "CollapseControlID", the CollapsiblePanel will
		/// toggle when this control is clicked.       
		/// </summary>
		[IDReferenceProperty(typeof(WebControl))]
		[DefaultValue("")]
		[SuppressMessage("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase", Justification = "Following ASP.NET AJAX pattern")]
		[ExtenderControlProperty]
		public string ExpandControlID { [DebuggerNonUserCodeAttribute] get { return m_ExpandControlID ?? string.Empty; } [DebuggerNonUserCodeAttribute] set { m_ExpandControlID = value; } }

		#endregion

		#region public bool AutoCollapse

		private bool m_AutoCollapse;

		/// <summary>
		/// If true, and the panel is in its 'expanded' state, the panel will
		/// automatically collapse when the mouse pointer moves off of the panel.
		/// </summary>
		[DefaultValue(false)]
		[ExtenderControlProperty]
		public bool AutoCollapse { [DebuggerNonUserCodeAttribute] get { return m_AutoCollapse; } [DebuggerNonUserCodeAttribute] set { m_AutoCollapse = value; } }

		#endregion

		#region public bool AutoExpand

		private bool m_AutoExpand;

		/// <summary>
		/// If true, and the panel is in its 'collapsed' state, the panel will
		/// automatically expand when the mouse pointer moves into the panel.
		/// </summary>
		[DefaultValue(false)]
		[ExtenderControlProperty]
		public bool AutoExpand { [DebuggerNonUserCodeAttribute] get { return m_AutoExpand; } [DebuggerNonUserCodeAttribute] set { m_AutoExpand = value; } }

		#endregion

		#region public int CollapsedSize

		private int m_CollapsedSize = -1;

		/// <summary>
		/// The size of the panel when it is in it's collapsed state.  To avoid flicker when your page
		/// initializes, set the initial height (or width) of your Panel control to match this value, and set the Collapsed property
		/// to 'true'.
		/// 
		/// The default value is -1, which indicates that the CollapsiblePanel should initialize the CollapsedSize based on the
		/// initial size of the object.
		/// </summary>
		/// 
		[DefaultValue(-1)]
		[ExtenderControlProperty]
		public int CollapsedSize { [DebuggerNonUserCodeAttribute] get { return m_CollapsedSize; } [DebuggerNonUserCodeAttribute] set { m_CollapsedSize = value; } }

		#endregion

		#region public int ExpandedSize

		private int m_ExpandedSize = -1;

		/// <summary>
		/// The size of the panel when it is in it's opened state.  To avoid flicker when your page
		/// initializes, set the initial width of your Panel control to match this value, and set the Collapsed property
		/// to 'false'.
		/// 
		/// The default value is -1, which indicates that the CollapsiblePanel should initialize the ExpandedSize based on the
		/// parent div offsetheight if aligned vertically and parentdiv offsetwidth if aligned horizonatally.        
		/// </summary>      
		/// 
		[DefaultValue(-1)]
		[ExtenderControlProperty]
		public int ExpandedSize { [DebuggerNonUserCodeAttribute] get { return m_ExpandedSize; } [DebuggerNonUserCodeAttribute] set { m_ExpandedSize = value; } }

		#endregion

		#region public bool ScrollContents

		private bool m_ScrollContents;

		/// <summary>
		/// Determines whether the contents of the panel should be scrolled or clipped if they do not fit into
		/// the expanded size.
		/// </summary>
		[DefaultValue(false)]
		[ExtenderControlProperty]
		public bool ScrollContents { [DebuggerNonUserCodeAttribute] get { return m_ScrollContents; } [DebuggerNonUserCodeAttribute] set { m_ScrollContents = value; } }

		#endregion

		#region public bool SuppressPostBack

		private bool m_SuppressPostBack;

		/// <summary>
		/// Determines whether the CollapsiblePanelBehavior should suppress the click operations of the controls
		/// referenced in CollapseControlID and/or ExpandControlID.  
		/// 
		/// By default, this value is false, except for anchor ("A") tags.
		/// </summary>
		[DefaultValue(false)]
		[ExtenderControlProperty]
		public bool SuppressPostBack { [DebuggerNonUserCodeAttribute] get { return m_SuppressPostBack; } [DebuggerNonUserCodeAttribute] set { m_SuppressPostBack = value; } }

		#endregion

		#region public bool Collapsed

		private bool m_Collapsed;

		/// <summary>
		/// Signals the initial collapsed state of the control.  Note this will not cause
		/// an expanded control to collapse at initialization, but rather tells the extender
		/// what the initial state of the Panel control is. 
		/// </summary>
		[DefaultValue(false)]
		[ExtenderControlProperty]
		public bool Collapsed { [DebuggerNonUserCodeAttribute] get { return m_Collapsed; } [DebuggerNonUserCodeAttribute] set { m_Collapsed = value; } }

		#endregion

		#region public string CollapsedText

		private string m_CollapsedText;

		/// <summary>
		/// The text to display in the collapsed state.  When the panel is collapsed,
		/// the internal contents (anything between the start and ending tags) of the control referenced by
		/// the TextLabelID property will be replaced with this text.  This collapsed text is also used
		/// as the alternate text of the image if ImageControlID is set.
		/// </summary>
		[DefaultValue("")]
		[ExtenderControlProperty]
		public string CollapsedText { [DebuggerNonUserCodeAttribute] get { return m_CollapsedText ?? string.Empty; } [DebuggerNonUserCodeAttribute] set { m_CollapsedText = value; } }

		#endregion

		#region public string ExpandedText

		private string m_ExpandedText;

		/// <summary>
		/// The text to display in the expanded state.  When the panel is expanded,
		/// the internal contents (anything between the start and ending tags) of the control referenced by
		/// the TextLabelID property will be replaced with this text.  This expanded text is also used
		/// as the alternate text of the image if ImageControlID is set.
		/// </summary>        
		[DefaultValue("")]
		[ExtenderControlProperty]
		public string ExpandedText { [DebuggerNonUserCodeAttribute] get { return m_ExpandedText ?? string.Empty; } [DebuggerNonUserCodeAttribute] set { m_ExpandedText = value; } }

		#endregion

		#region public string TextLabelID

		private string m_TextLabelID;

		/// <summary>
		/// The ID of a label control to display the current state of the Panel.  When the collapsed state of the 
		/// panel changes, the entire HTML contents (anything between the start and ending tags of the label) will be replaced
		/// with the status text.
		/// </summary>
		[IDReferenceProperty(typeof(Label))]
		[DefaultValue("")]
		[SuppressMessage("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase", Justification = "Following ASP.NET AJAX pattern")]
		[ExtenderControlProperty]
		public string TextLabelID { [DebuggerNonUserCodeAttribute] get { return m_TextLabelID ?? string.Empty; } [DebuggerNonUserCodeAttribute] set { m_TextLabelID = value; } }

		#endregion

		#region public string ExpandedImage

		private string m_ExpandedImage;

		/// <summary>
		/// Image to be displayed when the Panel is expanded and the ImageControlID is set
		/// </summary>        
		[DefaultValue("")]
		[UrlProperty]
		[ExtenderControlProperty]
		public string ExpandedImage { [DebuggerNonUserCodeAttribute] get { return m_ExpandedImage ?? string.Empty; } [DebuggerNonUserCodeAttribute] set { m_ExpandedImage = value; } }

		#endregion

		#region public string CollapsedImage

		private string m_CollapsedImage;

		/// <summary>
		/// Image to be displayed when the Panel is collapsed and the ImageControlID is set
		/// </summary>        
		[DefaultValue("")]
		[UrlProperty]
		[ExtenderControlProperty]
		public string CollapsedImage { [DebuggerNonUserCodeAttribute] get { return m_CollapsedImage ?? string.Empty; } [DebuggerNonUserCodeAttribute] set { m_CollapsedImage = value; } }

		#endregion

		#region public string ImageControlID

		private string m_ImageControlID;

		/// <summary>
		/// The ID of an image control to display the current state of the Panel.  When the collapsed state of the 
		/// panel changes, the image source will be changed from the ExpandedImage to the CollapsedImage.  We also
		/// use the ExpandedText and CollapsedText as the image's alternate text if they are provided.
		/// </summary>
		[IDReferenceProperty(typeof(Image))]
		[DefaultValue("")]
		[SuppressMessage("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase", Justification = "Following ASP.NET AJAX pattern")]
		[ExtenderControlProperty]
		public string ImageControlID { [DebuggerNonUserCodeAttribute] get { return m_ImageControlID ?? string.Empty; } [DebuggerNonUserCodeAttribute] set { m_ImageControlID = value; } }

		#endregion

		#region public CollapsiblePanelExpandDirection ExpandDirection

		private CollapsiblePanelExpandDirection m_ExpandDirection = CollapsiblePanelExpandDirection.Vertical;

		/// <summary>
		/// The dimension to use for collapsing and expanding - vertical or horizontal.
		/// </summary>
		[DefaultValue(CollapsiblePanelExpandDirection.Vertical)]
		[ExtenderControlProperty]
		public CollapsiblePanelExpandDirection ExpandDirection { [DebuggerNonUserCodeAttribute] get { return m_ExpandDirection; } [DebuggerNonUserCodeAttribute] set { m_ExpandDirection = value; } }

		#endregion

		/*
		[EditorBrowsable(EditorBrowsableState.Never)]
		[SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", Justification = "Assembly is not localized")]
		public override void EnsureValid()
		{
			base.EnsureValid();

			if ((ExpandedText != null || CollapsedText != null) && TextLabelID == null)
			{
				throw new ArgumentException("If CollapsedText or ExpandedText is set, TextLabelID must also be set.");
			}
		}
		*/
	}
}
